package com.jprocms.module.cms.api;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.jpro.framework.common.pojo.CommonResult;
import com.jprocms.module.cms.api.vo.LicenseVO;
import com.jprocms.module.cms.util.EnvUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

@RestController // 提供 RESTful API 接口，给 Feign 调用

@Validated
public class LicenseApiImpl implements LicenseApi {

    @Override
    public CommonResult<LicenseVO> getLicense() {
        LicenseVO vo = new LicenseVO();
        vo.setAppid(System.getProperty("appId"));
        vo.setProductName(System.getProperty("productName"));
        vo.setProject(System.getProperty("project"));
        vo.setVersion(System.getProperty("version"));
        vo.setProductGrade(EnvUtil.getGrade());
        vo.setMacAddress(System.getProperty("macAddress"));
        final String expiration = System.getProperty("expiration");
        vo.setExpiration(LocalDateTimeUtil.parse(expiration, "yyyy-MM-dd"));
        return CommonResult.success(vo);
    }
}
